package com.ts.main.mini.exception;

import lombok.Getter;
import lombok.ToString;

/**
 * @Author:lk
 * @Date: 2025/5/15  00:38
 */
@Getter
@ToString
public enum ApiErrorCode implements IErrorCode{
    /**
     * 失败
     */
    FAILED(-1, "操作失败"),
    /**
     * 成功
     */
    SUCCESS(0, "执行成功");

    private final long code;
    private final String msg;

    ApiErrorCode(final long code, final String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ApiErrorCode fromCode(long code) {
        ApiErrorCode[] ecs = ApiErrorCode.values();
        for (ApiErrorCode ec : ecs) {
            if (ec.getCode() == code) {
                return ec;
            }
        }
        return SUCCESS;
    }
}
